<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    // 题目1: 对字符串进行排列组合, 
    // 得到所有字符的全排列组合(假设所有字符不重复)

    // 例如：permutation("abc") 
    // 返回 ["abc", "acb", "bac", "bca", "cab", "cba"]
    function permutation(str) {
        var result = [];
        if (str.length > 1) {
            for (var m = 0; m < str.length; m++) {
                var left = str[m];
                var rest = str.slice(0, m) + str.slice(m + 1, str.length);
                var preResult = permutation(rest);
                for (var i = 0; i < preResult.length; i++) {
                    var tmp = left + preResult[i]
                    result.push(tmp);
                }
            }
        } else if (str.length == 1) {
            result.push(str);
        }
        return result;
    }
    console.log(permutation("abc"));
</script>